package com.game.action;

import com.coment.po.Game;
import com.game.logic.fighting.pve.GameServiceImpl;
import com.game.logic.user.login.ILoginService;
import com.xs.action.annotate.ActionController;
import com.xs.action.annotate.ActionMethod;
import io.netty.channel.ChannelHandlerContext;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;

/// 0-首页
@RestController
@RequestMapping("/indexAction")
@ActionController(value = 0, name = "首页")
public class IndexAction {
   @Resource
   private ILoginService loginService;
   @Resource
   private GameServiceImpl gameServiceImpl;

   /**
    * 0.登录处理
    *
    * @param ctx         通道处理上下文
    * @param clientToken 客户端令牌
    * @return 登录结果
    */
   @GetMapping("/login")
   @ActionMethod(value = 0, name = "登录")
   public String loginHandler(
           ChannelHandlerContext ctx,
           @NotNull String clientToken,
           String apiType
   ) {
      return this.loginService.login(ctx,apiType, clientToken);
   }

   /**
    * 2.初始化游戏
    *
    * @param anchorInfoId 主播信息id
    * @param level        关卡等级(1-200)
    * @return 游戏实例
    */
   @GetMapping("/initializeGame")
   @ActionMethod(value = 2, name = "初始化游戏", token = {"roomId"})
   public Game initializeGame(@NotNull Integer anchorInfoId, Integer level) {
      return this.gameServiceImpl.initializeGame(anchorInfoId, level);
   }
}
